﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 状态模式_应用实例2
{
    abstract class State
    {
        public abstract void Working(Work w);
    }

    class ForenoonState : State
    {
        public override void Working(Work w)
        {
            if (w.Hour >= 8 && w.Hour <= 11)
            {
                Console.WriteLine("早上阳光明媚");
            }
            else
            {
                w.Set(new NoonState());
                w.Working();
            }
        }
    }

    class NoonState : State
    {
        public override void Working(Work w)
        {
            if (w.Hour >= 12 && w.Hour <= 13)
            {
                Console.WriteLine("中午昏昏欲睡");
            }
            else
            {
                w.Set(new AfternoonState());
                w.Working();            
            }
        }
    }

    class AfternoonState : State
    {
        public override void Working(Work w)
        {
            if (w.Hour >= 14 && w.Hour <= 18)
            {
                Console.WriteLine("下午无限期待（下班）");
            }
            else
            {
                w.Set(new EveningState());
                w.Working();                
            }
        }   
    }

    class EveningState : State
    {
        public override void Working(Work w)
        {
            if (w.Hour > 18)
            {
                Console.WriteLine("周公赴会");
            }
            else
            { 
                 //w.Set(new NoonState());
                 //w.Working();        
                Console.WriteLine("无匹配状态");
            }
        }   
    }
}
